﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace orderCreater.ben
{
    
    public partial class frmName : Form
    {
        public class name_sex
        {
            public string name;
            public string sex;
        }
        public List<name_sex> area_url = new List<name_sex>();
        public List<string> area_phones = new List<string>();
        public int tick_index = 0, area_index = 0; //
        public string leaders = "赵钱孙李张林陈周吴郑王冯褚卫蒋沈韩杨朱秦尤许何吕施孔曹严华金魏陶姜戚谢邹喻柏水窦章云苏潘葛奚范彭郎鲁韦昌马苗凤花方俞任袁柳酆鲍史唐费廉岑薛雷贺倪汤滕殷罗毕郝邬安常乐于时傅皮卞齐康伍余元卜顾孟平黄和穆萧尹姚邵湛汪祁毛禹狄米贝明臧计伏成戴谈宋茅庞熊纪舒屈项祝董梁杜阮蓝闵席季麻强贾路娄危江童颜郭梅盛刁钟徐邱骆高夏蔡田樊胡凌霍虞万支柯昝管卢莫经房裘缪干解应宗丁宣贲邓郁单杭洪包诸左石崔吉钮龚程嵇邢滑裴陆荣翁荀羊於惠甄曲家封芮羿储靳汲邴糜松井段富巫乌焦巴弓牧隗山谷车侯宓蓬全郗班仰秋仲伊宫宁仇栾暴甘钭厉戎祖武符刘景詹束龙叶幸司韶郜黎蓟薄印宿白怀蒲邰从鄂索咸籍赖卓蔺屠蒙池乔阴鬱胥能苍双闻莘党翟谭贡劳逄姬申扶堵冉宰郦雍卻璩桑桂濮牛寿通边扈燕冀郏浦尚农温别庄晏柴瞿阎充慕连茹习宦艾鱼容向古易慎戈廖庾终暨居衡步都耿满弘匡国文寇广禄阙东欧殳沃利蔚越夔隆师巩厍聂晁勾敖融冷訾辛阚那简饶空曾毋沙乜养鞠须丰巢关蒯相查后荆红游竺权逯盖益桓公万俟司马上官欧阳夏侯诸葛闻人东方赫连皇甫尉迟公羊澹台公冶宗政濮阳淳于单于太叔申屠公孙仲孙轩辕令狐钟离宇文长孙慕容鲜于闾丘司徒司空丌官司寇仉督子车颛孙端木巫马公西漆雕乐正壤驷公良拓跋夹谷宰父谷梁晋楚闫法汝鄢涂钦段干百里东郭南门呼延归海羊舌微生岳帅缑亢况郈有琴梁丘左丘东门西门商牟佘佴伯赏南宫墨哈谯笪年爱阳佟";
        public frmName()
        {
            InitializeComponent();
            webBrowser1.Navigate("http://www.qmsjmfb.com/");
        }
        private void button1_Click(object sender, EventArgs e)
        {
            foreach (HtmlElement ElementBody in webBrowser1.Document.GetElementsByTagName("input"))
            {
                if (ElementBody.GetAttribute("name") == "xing")
                {
                    ElementBody.SetAttribute("value", leaders[area_index].ToString());
                }
            }
            tick_index = 0;
            area_phones = new List<string>();
            listBox1.Items.Add(leaders[area_index].ToString());
            timer1.Enabled = true;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (tick_index > 10)
            {
                listBox1.Items.Clear();
                timer1.Enabled = false;
                File.WriteAllLines(@"D:\doc\name\" + area_phones[0] + ".txt", area_phones);
                if (area_index < leaders.Length)
                {
                    area_index++;
                    button1_Click(sender, e);
                }
                else
                {
                    listBox1.Items.Add("完");
                }
                return;
            }
            listBox1.Items.Add(tick_index.ToString());
            switch (tick_index % 2)
            {
                case 0:
                    foreach (HtmlElement ElementBody in webBrowser1.Document.GetElementsByTagName("input"))
                    {
                        if (ElementBody.GetAttribute("type") == "submit")
                        {
                            if (ElementBody.GetAttribute("value") == "点击生成")
                            {
                                ElementBody.InvokeMember("click");
                                webBrowser1.ScriptErrorsSuppressed = true;
                            }
                        }
                    }
                    break;
                case 1:
                    foreach (HtmlElement ElementBody in webBrowser1.Document.GetElementsByTagName("ul"))
                    {
                        if (ElementBody.GetAttribute("className") == "name_show")
                        {
                            foreach (HtmlElement li in ElementBody.GetElementsByTagName("li"))
                            {
                                area_phones.Add(li.InnerText+",男");
                            }
                        }
                    }
                    break;
            }
            tick_index++;
            
        }
    }
}
